package com.jdbc;

import java.sql.*;
import java.util.*;

/**
 * A simple sample class to illustrate how to use Stored Procedures/functions,
 * and use an Oracle ref cursor in Java. To use the sample code - you will have
 * to create a Connection object, and pass it as a parameter in the constructor
 * of the class.
 */

public class Tmif extends Object {
	Connection dbConnection;
	private String dbms;
	private String portNumber;
	private String serverName;

	public Tmif(Connection connection) {
		dbConnection = connection;
	}

	public List getAccountInterval(int fromAccount, int toAccount)
			throws Exception {
		CallableStatement cstmt = dbConnection
				.prepareCall("{? = call	SP_AML_TMIF(?)}");
		cstmt.setFetchSize(100);
		cstmt.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.CURSOR);
		cstmt.setString(2, "210118160009");
		cstmt.executeQuery();
		ResultSet rs = (ResultSet) cstmt.getObject(1);
		List accounts = new ArrayList();
		while (rs.next()) {
			accounts.add(rs.getString("account_no") + " - "
					+ rs.getString("name"));
		}
		rs.close();
		cstmt.close();
		return accounts;
	}

	public Connection getConnection() throws SQLException {
		Connection conn = null;
		Properties connectionProps = new Properties();
		connectionProps.put("user", "aml");
		connectionProps.put("password", "1234");

		conn = DriverManager.getConnection("jdbc:" + this.dbms + "://"
					+ this.serverName + ":" + this.portNumber + "/",
					connectionProps);
		System.out.println("Connected to database");
		return conn;
	}

}
